package com.cis467.mrball;

import android.content.Context;
import android.graphics.Canvas;

import com.cis467.mrball.parts.Level;

public class LevelSelectScreenManager extends ScreenManager {
	
	// Menu size constants
	private static final int NUM_BUTTONS = 3;

	// Side panel dimensions
	private int mBannerTextWidthOffset;
	private int mBannerTextHeightOffset;
	
	private int mButtonHeight;
	
	private int mButtonTextHeightOffset;
	private int mButtonTextWidthOffset;

	public LevelSelectScreenManager (Context context) {

		super(context, true);
	}

	public void setDimensions(int width, int height) {

		super.setDimensions(width, height);

		// Set up other dimensions
		mBannerTextHeightOffset = mBannerHeight/2 + SharedConstants.NORMAL_TEXT_SIZE/3;	
		mBannerTextWidthOffset = mBannerTextHeightOffset/3;

		int mBoardHeight = mTileSize*Level.FLOOR_ROWS;
		mButtonHeight = mBoardHeight / NUM_BUTTONS;
		
		mButtonTextHeightOffset = mButtonHeight/2 + SharedConstants.LARGE_TEXT_SIZE/3;
		mButtonTextWidthOffset = mSidePanelWidth/10;

	}

	public void draw(Canvas canvas, Level pLevel, String mode) {

		this.canvas = canvas;

		clearCanvas();

		renderLevel(pLevel);
		
		drawStatic();
		
		drawVisibleDynamic(pLevel);

		//TODO fix this
		drawBanner("No Name Yet");
		//drawBanner(pLevel.getName());

		drawSidePanel(mode);
	}

	public void drawBanner(String name) {

		// Draw the main panel box
		canvas.drawRect(0, 0, 
				mScreenWidth, mBannerHeight, 
				mPaintManager.getPaint(PaintManager.PANEL));

		// Draw the name container
		canvas.drawRect(MENU_BUFFER, MENU_BUFFER, 
				mScreenWidth - MENU_BUFFER, 
				mBannerHeight - MENU_BUFFER, 
				mPaintManager.getPaint(PaintManager.CONTAINER));

		// Draw the name label
		String levelName = "Level Name: " + name;
		canvas.drawText(levelName, 
				mBannerTextWidthOffset, mBannerTextHeightOffset, 
				mPaintManager.getPaint(PaintManager.TEXT_NORMAL));
	}

	public void drawSidePanel(String mode) {

		// Draw the main panel box
		canvas.drawRect(mSidePanelOffset, mBannerHeight, 
				mScreenWidth, mScreenHeight, 
				mPaintManager.getPaint(PaintManager.PANEL));

		// Draw the buttons
		for(int i = 0; i < NUM_BUTTONS; i++)
			canvas.drawRect(mSidePanelOffset + MENU_BUFFER, 
					mBannerHeight + i*mButtonHeight + MENU_BUFFER, 
					mScreenWidth - MENU_BUFFER, 
					mBannerHeight + (i+1)*mButtonHeight - MENU_BUFFER, 
					mPaintManager.getPaint(PaintManager.CONTAINER));
		
		// Draw the Previous label
		canvas.drawText("Next", 
				mSidePanelOffset + mButtonTextWidthOffset + MENU_BUFFER, 
				mBannerHeight + mButtonTextHeightOffset + MENU_BUFFER , 
				mPaintManager.getPaint(PaintManager.TEXT_LARGE));

		// Draw the Next label
		canvas.drawText("Previous", 
				mSidePanelOffset + mButtonTextWidthOffset + MENU_BUFFER, 
				mBannerHeight + mButtonHeight + mButtonTextHeightOffset + MENU_BUFFER , 
				mPaintManager.getPaint(PaintManager.TEXT_LARGE));
				
		// Draw the Play label
		canvas.drawText(mode, 
				mSidePanelOffset + mButtonTextWidthOffset + MENU_BUFFER, 
				mBannerHeight + 2*mButtonHeight + mButtonTextHeightOffset + MENU_BUFFER , 
				mPaintManager.getPaint(PaintManager.TEXT_LARGE));

	}

	public boolean isSideMenuTouch(int x) {

		return x >= mSidePanelOffset;
	}

	public boolean isNextButton(int y) {

		return y >= mBannerHeight && y < mBannerHeight + mButtonHeight;
	}
	
	public boolean isPrevButton(int y) {

		return y >= mBannerHeight + mButtonHeight && y < mBannerHeight + 2*mButtonHeight;
	}
	
	public boolean isPlayButton(int y) {

		return y >= mBannerHeight + 2*mButtonHeight;
	}
}
